package com.example.demo.config;

import com.example.demo.enums.ResultCodeEnum;
import com.example.demo.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;
@Slf4j
@RestControllerAdvice
public class ExceptionAdvise {

    @ExceptionHandler
    public Result handle(Exception e){
        log.error("发生异常: ",e);
        return Result.fail(e.getMessage());
    }


    @ExceptionHandler
    public Result handle(UnsupportedOperationException e){
        log.error("发生异常,e:",e.getMessage());
        return Result.fail(ResultCodeEnum.PARAM_INVALID.getCode(),e.getMessage());
    }

    @ExceptionHandler
    public Result handle(NoResourceFoundException e) {
        log.error("发生异常,e:", e.getResourcePath());
        return Result.fail(ResultCodeEnum.NO_RESOURCE.getCode(), e.getResourcePath());
    }

}
